import Taro, { Component } from "@tarojs/taro";
import { AtModal, AtModalContent, AtModalAction } from "taro-ui";
import {connect} from '@tarojs/redux'
import {Button} from '@tarojs/components'
import {onSubmitPlan,onCancelOverridePlan} from '../../actions/makePlan'

@connect(
    state=>state.makePlan,
    {onSubmitPlan,onCancelOverridePlan}
)
class OverridePlanModal extends Component {

    onCloseModal(){
      this.props.onCancelOverridePlan()
        Taro.atMessage({
            message:"已取消覆盖",
            type:'warning',
            duration:3000
        })
    }

    onOverride=()=>{
        this.props.onSubmitPlan({
            ...this.props.unsubmitedPlans[0],
            override:true
        })
    }

  render() {
    return (
      <AtModal isOpened closeOnClickOverlay={false} onCancel={()=>{}}>
        <AtModalContent>
          由于 {
              this.props.unsubmitedPlans[1].map((v)=>{
                  let arr=v.split('-');
                  return `${arr[0]}年${arr[1]}月${arr[2]}日`
              }).toString()
          } 都已经有计划了，您需要覆盖原先的计划吗？
        </AtModalContent>
        <AtModalAction>
          <Button onClick={this.onCloseModal}>取消</Button> <Button onClick={this.onOverride}>确定</Button>
        </AtModalAction>
      </AtModal>
    );
  }
}

export default OverridePlanModal;